package com.wanxi.servlet.news;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.VO.NewsClassVO;
import com.wanxi.VO.NewsVO;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.NewsClassService;
import com.wanxi.service.NewsService;
import com.wanxi.service.impl.NewsClassServiceImpl;
import com.wanxi.service.impl.NewsServiceImpl;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : 林子淳
 * @create 2023/3/2 18:31
 */
//@WebServlet("/back/news/findById")
public class NewsFindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        System.out.println("进入了修改后台");
        //2、接收前端传过来的值
        String id = req.getParameter("id");
        System.out.println("DeviceUpdateServlet的id="+id);
        ResultDTO resultDTO=null;
        try{
            //3、封装数据
            NewsVO newsVO = new NewsVO();
            newsVO.setId(Tool.strToInt(id));
            //4、调用逻辑层
            NewsService newsService = new NewsServiceImpl();
            //5、接收逻辑层返回的值
            resultDTO = newsService.findById(newsVO);

        }catch (Exception e){
            e.printStackTrace();
        }
        //6、把值返回给前端
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }
}
